/**
* v-hasPermi 操作权限处理
* 注释：hyf-2023/07/05
*/

import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    //获取到指令传入值
    const { value } = binding
    //所有权限字段
    const all_permission = "*:*:*";
    //当前用户权限
    const permissions = store.getters && store.getters.permissions
    //验证指令传入值是否正确有效
    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      //查看是否具有该操作权限
      const hasPermissions = permissions.some(permission => {
        return all_permission === permission || permissionFlag.includes(permission)
      })
      //没有权限进行移除操作
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }
}
